package aqr;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Factorial {

	public static void main(String[] args) {
		int number = 0;
		System.out.print("Enter the number to calculate factorial: ");
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			number = Integer.parseInt(br.readLine());
		} catch (IOException e) {
			System.out.println("Invalid Entry");
		}
		
		System.out.println("Iterative: The factorial of "+number+" is :"+factorial(number));
		System.out.println("Recursive: The factorial of "+number+" is :"+factorialRec(number));
	}
	
	public static int factorial(int num){
		if (num == 0) return 0;
		int factorial = 1;
		for (int i = 1; i <= num; i++) {
			factorial *= i;
		}
		return factorial;
	}
	
	public static int factorialRec(int num){
		if (num == 0) return 0;
		if (num == 1) return num;
		return factorialRec(num-1)*num;
	}
}
